
Java has three "address" classes:

  InetAddress represents ip addresses only,

  SocketAddress is abstract and represents ip + port,

  InetSocketAddress is concrete subclass of SocketAddress, represents ip + port + protocol.



In the Socket class:

getRemoteSocketAddress()   returns an InetSocketAddress subclass of SocketAddress

getLocalSocketAddress()    returns an InetSocketAddress subclass of SocketAddress


getPort()           should be called getRemotePort(), redundant with above methods

getLocalPort()      redundant with above methods


getInetAddress()    should be called getRemoteInetAddress(), somewhat redundant with above methods

getLocalAddress()   should be called getLocalInetAddress(),  somewhat redundant with above methods




Consider this documentation from the Socket class.

   getRemoteSocketAddress()
      Returns the address of the endpoint this socket is connected to, or null if it is unconnected.

   getLocalSocketAddress()
      Returns the address of the endpoint this socket is bound to, or null if it is not bound.

What does "endpoint" mean? What is the difference between "bound" and "connected"?





Notice that there are essentially three different kinds of constructors for Socket.
Why do two of the constructors refer to "stream socket" and two don't?
Does "stream socket" mean anything?

   Socket()
      Creates an unconnected socket.

   Socket(InetAddress address, int port)
      Creates a stream socket and connects it to the specified port number at the specified IP address.
   Socket(String host, int port)
      Creates a stream socket and connects it to the specified port number on the named host.

   Socket(InetAddress address, int port, InetAddress localAddr, int localPort)
      Creates a socket and connects it to the specified remote address on the specified remote port.
   Socket(String host, int port, InetAddress localAddr, int localPort)
      Creates a socket and connects it to the specified remote host on the specified remote port.


If you construct an unconnected Socket, then you need to bind() and connect()
the socket yourself. (Does that create a "stream socket"?)